package com.yf.exam.modules.exam.ext.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.yf.base.api.api.ApiRest;
import com.yf.base.api.api.controller.BaseController;
import com.yf.base.api.api.dto.BaseIdReqDTO;
import com.yf.base.api.api.dto.PagingReqDTO;
import com.yf.exam.modules.exam.ext.dto.*;
import com.yf.exam.modules.exam.ext.service.ExamWatchService;
import com.yf.exam.modules.paper.service.PaperService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
* <p>
* 监考管理控制器
* </p>
*
* @author 聪明笨狗
* @since 2020-07-25 16:18
*/
@Api(tags={"监考管理"})
@RestController
@RequestMapping("/api/exam/watch")
public class ExamWatchController extends BaseController {

    @Autowired
    private ExamWatchService baseService;

    @Autowired
    private PaperService paperService;


    @RequiresPermissions("exam:watch")
    @ApiOperation(value = "发送消息给单个用户")
    @PostMapping("/single-msg")
    public ApiRest sendSingleMsg(@RequestBody WatchMsgReqDTO reqDTO) {
        baseService.sendSingleMsg(reqDTO.getExamId(), reqDTO.getUserId(), reqDTO.getMessage());
        return super.success();
    }

    @RequiresPermissions("exam:watch")
    @ApiOperation(value = "发送消息给全部用户")
    @PostMapping("/batch-msg")
    public ApiRest sendBatchMsg(@RequestBody WatchMsgReqDTO reqDTO) {

        baseService.sendBatchMsg(reqDTO.getExamId(), reqDTO.getMessage());
        return super.success();
    }

    @RequiresPermissions("exam:watch")
    @ApiOperation(value = "监考统计数据", notes = "id传入考试ID")
    @PostMapping("/watch-stat")
    public ApiRest<WatchStatRespDTO> watchStat(@RequestBody BaseIdReqDTO reqDTO) {

        WatchStatRespDTO respDTO = baseService.watchStat(reqDTO.getId());
        return super.success(respDTO);
    }


    /**
     * 监考列表
     * @param reqDTO
     * @return
     */
    @RequiresPermissions("exam:watch")
    @ApiOperation(value = "监考列表")
    @PostMapping("/watch-paging")
    public ApiRest<IPage<WatchUserRespDTO>> watchPaging(@RequestBody PagingReqDTO<WatchUserReqDTO> reqDTO) {

        //分页查询并转换
        IPage<WatchUserRespDTO> page = baseService.watchPaging(reqDTO);

        return super.success(page);
    }


    /**
     * 监考列表
     * @param reqDTO
     * @return
     */
    @RequiresPermissions("exam:watch")
    @ApiOperation(value = "已交卷列表")
    @PostMapping("/hand-paging")
    public ApiRest<IPage<WatchPaperRespDTO>> handPaging(@RequestBody PagingReqDTO<WatchPaperReqDTO> reqDTO) {

        //分页查询并转换
        IPage<WatchPaperRespDTO> page = baseService.handPaging(reqDTO);

        return super.success(page);
    }


    /**
     * 强制交卷
     * @param reqDTO
     * @return
     */
    @RequiresPermissions("exam:watch")
    @ApiOperation(value = "强制交卷", notes = "管理员强制考生交卷")
    @PostMapping("/force-hand")
    public ApiRest forceHand(@RequestBody WatchHandReqDTO reqDTO) {
        baseService.forceHand(reqDTO.getPaperId(), reqDTO.getMessage());
        return super.success();
    }

    /**
     * 强制交卷
     * @param reqDTO
     * @return
     */
    @RequiresPermissions("exam:watch")
    @ApiOperation(value = "全部交卷", notes = "全部学员强制交卷")
    @PostMapping("/force-hand-all")
    public ApiRest forceHandAll(@RequestBody WatchHandReqDTO reqDTO) {
        paperService.handAll(reqDTO.getExamId(), reqDTO.getExState(), reqDTO.getMessage());
        return super.success();
    }




}
